1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class Cloud : MonoBehaviour {
6
7     
public float speed;
8
9     
private float maxTop, maxBottom;
10     
private Vector3 target;
11
12     
void Awake(){
13         InitializeVariables ();
14     }
15
16     
// Use this for initialization
17     
void Start () {
18
19     }
20     
21     
// Update is called once per frame
22     
void Update () {
23         
if (transform.position != target) {
24             transform.position = Vector3.MoveTowards (transform.position, target, speed * Time.deltaTime);
25         }
else {
26             Destroy (gameObject);
27             GameplayController.instance.InitializeSpawners ();
28         }
29     }
30
31     
void InitializeVariables(){
32         Vector3 topBound = Camera.main.ViewportToWorldPoint (
new Vector3 (0, 1, 0));
33         Vector3 bottomBound = Camera.main.ViewportToWorldPoint (
new Vector3 (0, 0, 0));
34         Vector3 temp = transform.position;
35         target =
new Vector3(0, maxBottom - 20, 0);
36         maxTop = topBound.y;
37         maxBottom = bottomBound.y;
38
39         temp.y = maxTop +
11;
40     
41         transform.position = temp;
42
43     }
44         
45 }


Use this for initialization

Update is called once per frame



Gõ tìm kiếm nhanh...